package com.vint.leetcode;

import com.vint.common.TreeNode;

/*
 * Trim tree
 */
public class Leetcode669 {

    public TreeNode trimBST(TreeNode root, int L, int R) {
        if(null == root){
            return root;
        }
        if(root.val<L){
            return trimBST(root.right,L,R);
        }
        if(root.val>R){
            return trimBST(root.left,L,R);
        }
        /*
        if(root.val == L){
            root.left = null;
        }
        if(root.val == R){
            root.right= null;
        }
        */
        root.left = trimBST(root.left,L,root.val);
        root.right= trimBST(root.right,root.val,R);
        return root;
    }

    public static void main(String[] args) {
        TreeNode root1 = TreeNode.mockBinarySearchTree();
        Leetcode669 sixSixNine = new Leetcode669();
        TreeNode ret = sixSixNine.trimBST(root1, 3, 6);
        System.out.println("success!");
    }
  }
